package com.iflytek.controller;

import com.iflytek.entity.Carts;
import com.iflytek.entity.User;
import com.iflytek.service.CartsService;
import com.iflytek.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class CarController {

    @Autowired
    private CartsService cartsService;

    @Autowired
    private UserService userService;

    @GetMapping("/goods")
    public String goods(Model model) {
        List<Carts> carts = cartsService.list();
        model.addAttribute("cars", carts);
        return "goods";
    }

    @GetMapping("/goodsDetail")
    public String goodsDetail(Integer id, Model model) {
        Carts cart = cartsService.getById(id);
        model.addAttribute("cart", cart);
        return "goods_detail";
    }

    @GetMapping("/goodsOrder")
    public String toGoodsOrder(Integer id, Model model) {
        Carts cart = cartsService.getById(id);
        model.addAttribute("cart", cart);

        List<User> users = userService.list();

        model.addAttribute("users", users);
        return "goods_order";
    }

}
